package com.tablepet.adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.tablepet.R;
import com.tablepet.bean.ShopBean;

import java.util.List;
public class ShopAdapter extends RecyclerView.Adapter<ShopAdapter.VH> {
    private final List<ShopBean> mList;
    public ShopAdapter(List<ShopBean> mList) {
        this.mList = mList;
    }
    @NonNull
    @Override
    public VH onCreateViewHolder(ViewGroup parent, int viewType) { return new VH(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_shop, parent, false)); }
    @Override
    public void onBindViewHolder(@NonNull VH vh, int position) {
        vh.name.setText(mList.get(position).name);
        vh.state.setText(mList.get(position).state);
        vh.iv.setImageResource(mList.get(position).id);
    }
    @Override
    public void onViewAttachedToWindow(@NonNull VH vh) { super.onViewAttachedToWindow(vh); }
    @Override
    public int getItemCount(){
        return mList.size();
    }
    static class VH extends RecyclerView.ViewHolder {
        TextView name,state;
        ImageView iv;
        public VH(View itemView) {
            super(itemView);
            iv=itemView.findViewById(R.id.item_shop_iv);
            name=itemView.findViewById(R.id.item_shop_name);
            state=itemView.findViewById(R.id.item_shop_state);
        }
    }
}